#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>

void Conv14x4(float *dst, float *input, float *weight, size_t src_depth, size_t dst_step, size_t dst_depth, size_t width);

void main()
{
    int iw = 448;
    int ih = 448;
    int ic = 64;
    int oc = 32;
    int kw = 3;
    int kh = 3;
    int ow = 448;
    int oh = 448;

    // do not initialize anything, to hide cache miss message from
    // cg_annotate cachegrind.out.xxx --auto=yes
    int packed_input_size = ow * oh * kw * kh * ic;
    float *packed_input_1 = (float *) malloc(packed_input_size * sizeof(float));

    int packed_weight_size = oc * kw * kh * ic;
    float *packed_weight_1 = (float *) malloc(packed_weight_size * sizeof(float));

    int out_size = ow * oh * oc;
    float *output_1 = (float *) malloc(out_size * sizeof(float));

    // 14x4
    int batches = ow * oh / 14;
    struct timeval start, end;
    double duration = 0;
    gettimeofday(&start, NULL);
    for (int i = 0; i < batches; ++i) {
        Conv14x4(output_1, packed_input_1 + i * kw * kh * 4, packed_weight_1, kw * kh * ic / 4, ow * oh * 4, oc / 4, 0);
    }
    gettimeofday(&end, NULL);
    duration = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
    printf("%f\n", duration);
}